package com.tvunetworks.center.device.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tvunetworks.center.common.model.UserDeviceRecord;
import com.tvunetworks.center.common.model.vo.UserDeviceRecordVo;
import com.tvunetworks.center.device.mapper.UserDeviceRecordMapper;
import com.tvunetworks.center.device.model.param.UserDeviceRecordParam;
import com.tvunetworks.center.device.service.UserDeviceRecordService;
import com.tvunetworks.center.device.util.DistributedGlobalIdUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
/**
 * @program:
 * @description:
 * @author HenryChen
 * @create: 7/26/2019 4:02 PM
 **/
@Slf4j
@Service
public class UserDeviceRecordServiceImpl implements UserDeviceRecordService {
    @Autowired
    private UserDeviceRecordMapper userDeviceRecordMapper;
    @Autowired
    private DistributedGlobalIdUtil distributedGlobalIdUtil;
    @Override
    public PageInfo<UserDeviceRecordVo> list(UserDeviceRecordParam userDeviceRecordParam) {
        PageHelper.startPage(userDeviceRecordParam.getPageNum(),userDeviceRecordParam.getPageSize());
        List<UserDeviceRecordVo> list = userDeviceRecordMapper.list(userDeviceRecordParam);
        return new PageInfo<UserDeviceRecordVo>(list);
    }

    /**
     *
     * @param userDeviceRecord userDeviceRecord
     */
    public void saveRecord(UserDeviceRecord userDeviceRecord) {
        try {
            userDeviceRecord.setId(distributedGlobalIdUtil.netxId()+"");
            userDeviceRecord.setDeleteFlag(0);
            userDeviceRecord.setCreateTime(System.currentTimeMillis()+"");
            userDeviceRecordMapper.insert(userDeviceRecord);
        } catch (Exception e) {
            log.error("saveRecord Exceptipn param", JSONObject.toJSONString(userDeviceRecord));
            log.error("saveRecord Exceptipn:[{}]",e);
        }

    }
}
